
import AuthenticationService from '../../shared/services/authentication-service';
import HttpRequestService from '../../shared/services/http-request-service';
import TokenService from '../../shared/services/token-service';

export default class AuthService {
  private static readonly url = '/authentication';

  /**
   * Login with provided [username] and [password]. The user basic info will be return.
   */
  static async login(username: string, authCode: string): Promise<any> {
    // TODO: Applies real deviceInfo & systemInfo as needed.
    const response: any = await HttpRequestService.post(`${this.url}/authCodeLogin`, {
      registrationAllowed: "登录 / 注册",
      username: username,
      authCode: authCode,
      deviceInfo: {
        id: "angular-test",
        brand: "Google",
        model: "model",
        productName: "productName",
        systemName: "systemName",
        systemVersion: "systemVersion",
      },
    });

    return response.payload;
  }

  static logout() {
    // Removes local user info.
    AuthenticationService.removeUserInfo();

    // Removes local token info.
    TokenService.removeToken();
  }

  static async sendAuthCode(data: any): Promise<any> {
    const response: any = await HttpRequestService.post(
      '/smsCode/sendAuthCode',
      data
    );
    
    return response.payload.code;
  }

  /**
 * 测试接口
 */
  static async testApi(data: any): Promise<any> {
    const response: any = await HttpRequestService.get(
      '/user/queryAccountGroupUsers',
      data
    )

    return response.payload;
  }
} 